<%@ page import="java.util.Date" %>
<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="../include/tag.jsp" %>
<!DOCTYPE html>
<html lang="zh">
<head>
    <title>打卡项目管理</title>
    <link rel="stylesheet" href="${ctx}/css/common/list.css">
    <link rel="stylesheet" href="${ctx}/css/common/table.css">
    <%@include file="../include/commonFile.jsp" %>
</head>
<body>
<!--头部-->
<%@include file="../include/header.jsp" %>
<div class="index-outside">
    <%@include file="../include/sidebar.jsp" %>
    <!--内容-->
    <section>
        <div class="section-main">
            <form class="layui-form" action="${ctx}/sign/project/list.do" id="myForm" method="post">
                <input type="hidden" name="pageNo" id="pageNo"/>
                <div class="f-search-bar">
                    <div class="search-container">
                        <ul class="search-form-content">
                            <li class="form-item-inline"><label class="search-form-lable">项目名称</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="title" autocomplete="off" class="layui-input"
                                           value="${project.title}" placeholder="请输入查询项目名称">
                                </div>
                            </li>
                            <li class="form-item-inline"><label class="search-form-lable">发布者</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="memberName" autocomplete="off" class="layui-input"
                                           value="${input.memberName}" placeholder="请输入查询项目发布者">
                                </div>
                            </li>
                            <li class="form-item-inline">
                                <label class="search-form-lable">项目状态</label>
                                <div class="layui-input-inline" style="width: 165px">
                                    <select name="timeStatus">
                                        <option value="">全部</option>
                                        <option value="0" ${input.timeStatus == 0 ? 'selected' : ''}>进行中</option>
                                        <option value="1" ${input.timeStatus == 1 ? 'selected' : ''}>已截止</option>
                                        <option value="2" ${input.timeStatus == 2 ? 'selected' : ''}>未开始</option>
                                    </select>
                                </div>
                            </li>
                            <li class="form-item-inline">
                                <div class="sub-btns" style="width: 262px; text-align: right;">
                                    <a class="layui-btn layui-btn-danger"
                                       href="javascript:submitFunction('#myForm')">查询</a>
                                    <a class="layui-btn layui-btn-normal"
                                       href="javascript:resetFunction('#myForm')">重置</a>
                                </div>
                            </li>
                        </ul>
                        <ul class="search-form-content">
                            <li class="form-item"><label class="search-form-lable">发布时间</label>
                                <div class="check-btn-inner" id="timeType">
                                    <a id="all" href="javascript:void(0);"
                                       onclick="setTimeType($(this),0,'#myForm')" ${empty input.timeType || input.timeType == 0 ? 'class="active"' : ''}>全部</a>
                                    <a href="javascript:void(0);"
                                       onclick="setTimeType($(this),1,'#myForm')" ${input.timeType == 1 ? 'class="active"' : ''}>今天</a>
                                    <a href="javascript:void(0);"
                                       onclick="setTimeType($(this),2,'#myForm')" ${input.timeType == 2 ? 'class="active"' : ''}>本周内</a>
                                    <a href="javascript:void(0);"
                                       onclick="setTimeType($(this),3,'#myForm')" ${input.timeType == 3 ? 'class="active"' : ''}>本月内</a>
                                    <input type="hidden" name="timeType" value="${input.timeType}"/>
                                </div>
                                <div class="layui-inline">
                                    <div class="layui-input-inline">
                                        <input class="layui-input" type="text" name="createStart"
                                               value="${input.createStart}" placeholder="开始日">
                                    </div>
                                    -
                                    <div class="layui-input-inline">
                                        <input class="layui-input" type="text" name="createEnd"
                                               value="${input.createEnd}" placeholder="截止日">
                                    </div>
                                </div>
                            </li>
                        </ul>
                    </div>
                </div>
            </form>
            <c:set var="nowDate" value="<%=new Date()%>"/>
            <div class="c-time-list-content">
                <ul>
                    <c:if test="${page.totalCount == 0}">
                        <div class="f16 tc mt15">还没有数据，请点击右上角的“发布打卡项目”，发布和编辑内容</div>
                    </c:if>
                    <c:forEach var="project" items="${list}">
                        <li>
                            <div class="detail-content">
                                <a class="act-logo common-img">
                                    <img src="<c:if test="${project.projectLogo != null}">${project.projectLogo}?imageMogr2/auto-orient/crop/200x150</c:if>"
                                         alt=""
                                         onerror="txz.errImg(this)" onload="txz.imgLoad(this)">
                                </a>
                                <div class="detail">
                                    <div class="act-title">
                                        <c:choose>
                                            <c:when test="${project.startTime > nowDate}">
                                                <span class="status f20 green">未开始</span>
                                            </c:when>
                                            <c:when test="${project.endTime > nowDate}">
                                                <span class="status f20 red">进行中</span>
                                            </c:when>
                                            <c:when test="${project.endTime < nowDate}">
                                                <span class="status f18 dark">已截止</span>
                                            </c:when>
                                        </c:choose>
                                        <a class="title f18 ell db">${project.title}</a>
                                    </div>
                                    <div>
                                        <p class="act-price">
                                                <%--<span style="margin-right: 10px;">
                                                    报名费用：
                                                    <c:if test="${project.price == 0.0}">
                                                        <b class="active-red">免费</b>
                                                    </c:if>
                                                    <c:if test="${project.price > 0.0}">
                                                        <b class="active-red"> ${project.price}</b>元/位
                                                    </c:if>
                                                </span>--%>
                                            <span>报名人数：<b class="active-red">${project.passNum}</b>人</span>
                                            <span>发布者：<b class="active-red">${project.authorName}</b></span>
                                        </p>
                                        <p class="act-price">
                                            <span style="margin-right: 5px">
                                                开始时间：<fmt:formatDate value="${project.startTime}"
                                                                     pattern="yyyy-MM-dd HH:mm"/>
                                            </span>
                                            <span>
                                                结束时间：<fmt:formatDate value="${project.endTime}"
                                                                     pattern="yyyy-MM-dd HH:mm"/>
                                            </span>
                                        </p>
                                        <p class="act-price">
                                            <span>
                                                发布时间：<fmt:formatDate value="${project.createDate}"
                                                                     pattern="yyyy-MM-dd HH:mm"/>
                                            </span>
                                        </p>
                                    </div>
                                    <div class="opts-btns tb-opts" style="width:475px;">
                                        <div class="comm-opts">
                                            <a class="qr-btn" href="javascript:txz.openQrDialog({
												title:'扫码二维码可预览分享',
												detailList:[{
													title:'打卡二维码',
													url:'${project.qrCode}'
												}]
											})"><i class="iconfont icon-qrcode btn-icon"></i> 二维码</a>
                                            <a href="${ctx}/sign/project/view.do?id=${project.id}"> <i
                                                    class="iconfont icon-edit btn-icon"></i>
                                                编辑
                                            </a>
                                            <a href="javascript:txz.deleteObject('确定删除项目？', '${ctx}/sign/project/delete.do?id=${project.id}')">
                                                <i class="iconfont icon-delete btn-icon"></i> 删除
                                            </a>
                                            <a href="${ctx}/sign/group/list.do?projectId=${project.id}"> <i
                                                    class="iconfont icon-group btn-icon"></i>
                                                队伍管理
                                            </a>
                                            <a href="${ctx}/sign/member/list.do?projectId=${project.id}"> <i
                                                    class="iconfont icon-people btn-icon"></i>
                                                成员管理
                                            </a>
                                            <a href="${ctx}/sign/member/check/list.do?projectId=${project.id}"> <i
                                                    class="iconfont menu-icon icon-profile"></i>
                                                成员审核
                                            </a>
                                            <a href="${ctx}/sign/member/rankList.do?projectId=${project.id}"> <i
                                                    class="iconfont icon-rank btn-icon"></i>
                                                数据查看
                                            </a>
                                            <a href="javascript:reviseProject('${project.id}')">校正数据</a>
                                            <a href="javascript:createQrCode('${project.id}')">生成二维码</a>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </li>
                    </c:forEach>
                </ul>
            </div>
            <div class="page-content">
                <c:if test="${page.totalCount > 0}">
                    <div class="l page-totalcount"><span class="f14 red">共<b
                            id="totalCount">${page.totalCount}</b>条记录</span></div>
                </c:if>
                <div id="page_content" class="page-container"></div>
            </div>
        </div><!--底部-->
        <%@include file="../include/footer.jsp" %>
    </section>
</div>

<script type="text/javascript" src="${ctx}/script/common/table_option.js"></script>
<script type="text/javascript" src="${ctx}/script/common/list.js"></script>
<script type="text/javascript">

    $(function () {
        //加载分页
        loadPageNew({
            elem: 'page_content',
            totalCount: '${page.totalCount}',
            limit: '${page.limit}',
            page: '${page.page}'
        });
        //加载日历
        layui.use(['laytpl', 'laypage', 'element', 'laydate'], function () {
            var laytpl = layui.laytpl, laydate = layui.laydate, laypage = layui.laypage, element = layui.element;
            element.on('tab(type)', function (data) {
                if (data.index == 0) {
                    $('#status').val(0);
                    $('#myForm').submit();
                } else if (data.index == 1) {
                    $('#status').val(1);
                    $('#myForm').submit();
                }
            });

            // 查询开始日期
            var start = {
                elem: 'input[name=s_start]'
            };

            var end = {
                elem: 'input[name=s_end]'
            };
            laydate.render(start);
            laydate.render(end);

            // 查询发布日期
            var start = {
                elem: 'input[name=createStart]'
            };

            var end = {
                elem: 'input[name=createEnd]'
            };
            laydate.render(start);
            laydate.render(end);
        });

    })

    // 校正项目数据
    function reviseProject(projectId) {
        layer.confirm('确定要校正项目数据？', {
            icon: 3,
            title: '系统提示'
        }, function (index) {
            $.post("${ctx}/sign/project/reviseProject.do", {
                projectId: projectId
            }, function (data) {
                if (data.success == true) {
                    util.layerMsgSuccess("校正成功", function () {
                        window.location.reload();
                    })
                } else {
                    util.layerMsgError("校正失败")
                }
            });
        });
    }

    // 生成项目二维码
    function createQrCode(projectId) {
        layer.confirm('确定要生成项目二维码？', {
            icon: 3,
            title: '系统提示'
        }, function (index) {
            $.post("${ctx}/sign/project/checkXcxQrCode.do", {
                projectId: projectId
            }, function (data) {
                if (data.success == true) {
                    util.layerMsgSuccess("生成成功", function () {
                        window.location.reload();
                    })
                } else {
                    util.layerMsgError("生成失败")
                }
            });
        });
    }
</script>
<script type="text/javascript">
    txz.initHeader({
        nav: [{
            name: '打卡项目管理',
            curr: true
        }],
        btns: [{
            name: '发布打卡项目',
            href: '${ctx}/sign/project/view.do',
            icon: 'add'
        }]
    });
</script>
</body>
</html>